﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using WpfApp4.Models;

namespace WpfApp4
{
    /// <summary>
    /// UrlInputWindow.xaml 的交互逻辑
    /// </summary>
    public partial class UrlInputWindow : Window
    {
        public UrlInputWindow()
        {
            InitializeComponent();
            urlTxb.Text = ApplicationConfigSetting.CurrentUrl;
        }

        private void ConfirmBtnClick(object sender, RoutedEventArgs e)
        {
            Confirm();
        }

        private void CancelBtnClick(object sender, RoutedEventArgs e)
        {
            Cancel();
        }

        private void EnterKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                Confirm();
            }
            else if (e.Key == Key.Escape)
            {
                Cancel();
            }
        }

        private void Confirm()
        {
            ApplicationConfigSetting.CurrentUrl = urlTxb.Text;
            this.DialogResult = true;
            this.Close();
        }

        private void Cancel()
        {
            this.DialogResult = false;
            this.Close();
        }

        private void SaveBtnClick(object sender, RoutedEventArgs e)
        {

        }
    }
}
